package com.rop.znyx.sys.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rop.znyx.common.result.Result;
import com.rop.znyx.model.sys.RegionWare;
import com.rop.znyx.sys.service.RegionWareService;
import com.rop.znyx.vo.sys.RegionWareQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 城市仓库关联表 前端控制器
 * </p>
 *
 * @author rop
 * @since 2023-06-22
 */

@Api(tags = "城市仓库关联管理")
@RestController
@RequestMapping("admin/sys/regionWare")
@RequiredArgsConstructor

public class RegionWareController {


    private final RegionWareService regionWareService;

    /**
     * 开通区域列表
     */
    @ApiOperation(value = "获取开通区域列表")
    @GetMapping("{page}/{limit}")
    public Result<IPage<RegionWare>> index(
            @ApiParam(name = "page", value = "当前页码", required = true) @PathVariable("page") Long page,
            @ApiParam(name = "limit", value = "每页记录数", required = true) @PathVariable("limit") Long limit,
            RegionWareQueryVo regionWareQueryVo) {

        Page<RegionWare> pageParam = new Page<>(page, limit);

        IPage<RegionWare> pageModel = regionWareService.selectPage(pageParam, regionWareQueryVo);

        return Result.ok(pageModel);
    }

    /**
     * 添加开通区域
     */
    @ApiOperation(value = "新增")
    @PostMapping("save")
    public Result<Boolean> save(@RequestBody RegionWare regionWare) {
        regionWareService.saveRegionWare(regionWare);
        return Result.ok();
    }

    /**
     * 删除开通区域
     */
    @ApiOperation("删除开通区域")
    @DeleteMapping("remove/{id}")
    public Result<Boolean> remove(@PathVariable("id") Long id) {
        boolean isSuccess = regionWareService.removeById(id);
        return isSuccess ? Result.ok() : Result.fail();
    }

    /**
     * 取消开通区域
     */
    @ApiOperation("取消开通区域")
    @PostMapping("updateStatus/{id}/{status}")
    public Result<Boolean> updateStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        Boolean isSuccess = regionWareService.updateStatus(id, status);
        return isSuccess ? Result.ok() : Result.fail();
    }

}

